/**
 * Created by Jie on 2017/2/8.
 */

module.exports = {
    time:function () {
        var timestamp = Date.parse(new Date());
        return timestamp/1000;
    },
    isHave:function (_content,_checkTxt) {
        return _content.indexOf(_checkTxt)>0;
    },
    addObj:function (_obj,_user,_type) {
        if(_type == 1){  //type1添加 2修改 3删除 4其他操作
            _obj.createId = _user.id;
            _obj.createTime = times();
        }else {
            _obj.updateId = _user.id;
            _obj.updateTime = times();
        }
        return _obj;
    },
    getIds:function (_list,_attr) {
        var ids = [];
        for(var i=0;i<_list.length;i++){
            ids.push(_list[i][_attr]);
        }
        return ids;
    },
    getAttrValById:function(_id,_attr,_list){
        var val = '';
        for(var i=0;i<_list.length;i++){
            if(_id == _list[i]['id']){
                val = _list[i][_attr];
                break;
            }
        }
        return val;
    }
};

function times() {
    var timestamp = Date.parse(new Date());
    return timestamp/1000;
}